package com.dmooo.ymx.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dmooo.ymx.R;
import com.dmooo.ymx.bean.PDDBean;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.text.DecimalFormat;
import java.util.List;

/**
 * 开发者：wmm
 * 时间:2018/11/21 18:22
 * 说明：
 */
public class PddRecyclerAdapter extends CommonAdapter<PDDBean> {
    DecimalFormat df=new DecimalFormat("0.00");
    private ShopRecyclerAdapter.OnDeleteClickLister mDeleteClickListener;
    public PddRecyclerAdapter(Context context, int layoutId, List<PDDBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder,PDDBean item, int position) {
        //设置图片
        ImageView imageView = holder.getView(R.id.image);
        Glide.with(mContext).load(item.getGoods_thumbnail_url()).error(R.drawable.no_banner).dontAnimate().into(imageView);
        ((TextView)holder.getView(R.id.title_child)).setText(item.getGoods_name());
        holder.setText(R.id.tx2, "￥" +df.format(Double.valueOf(df.format(Float.valueOf(item.getMin_normal_price())/100))-Double.valueOf(df.format(Float.valueOf(item.getCoupon_discount())/100))));
        TextView tx2_2 = holder.getView(R.id.tx2_2);
//        df.format(Float.valueOf(item.getMin_normal_price())/100))
        //设置删除线
        tx2_2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tx2_2.setText("原价:￥" + df.format(Float.valueOf(item.getMin_normal_price())/100));
        TextView tx3 = holder.getView(R.id.tx3);
        tx3.setText(df.format(Float.valueOf(item.getCoupon_discount())/100) + "");
        holder.setText(R.id.tx4, "奖:"+df.format(Float.valueOf(item.getCommission()==null?"0":item.getCommission())/100)+ "元");
//        if (Long.valueOf(item.getSold_quantity()) < 1000) {
            holder.setText(R.id.tx5, "销量:"+item.getSales_tip());
//        } else {
//            holder.setText(R.id.tx5, "销量:" + df.format(Long.valueOf(item.getSold_quantity()) / 10000) + "万");
//        }
        holder.getView(R.id.tv_delete).setTag(position);
        holder.getView(R.id.tv_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDeleteClickListener != null) {
                    mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                }
            }
        });
    }
    public void setOnDeleteClickListener(ShopRecyclerAdapter.OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
}
